package org.example.stream;

import org.example.entity.Hero;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Stream09 {
    public static void main(String[] args) {
        Stream<Hero> heroStream = Stream.of(
                new Hero("独孤求败", 100),
                new Hero("令狐冲", 90),
                new Hero("风清扬", 98),
                new Hero("东方不败", 98),
                new Hero("方证", 92),
                new Hero("任我行", 92),
                new Hero("冲虚", 90),
                new Hero("向问天", 88),
                new Hero("不戒", 88)
        );
//        Map<Integer, List<Hero>> map = heroStream.collect(Collectors.groupingBy(h -> h.getName().length(), Collectors.toList()));
        Map<Integer, List<Integer>> map = heroStream.collect(Collectors.groupingBy(h -> h.getName().length(), Collectors.mapping(Hero::getStrength,Collectors.toList())));
        for (Map.Entry<Integer, List<Integer>> entry : map.entrySet()) {
            System.out.println(entry);
        }
    }
}
